<template>
  <view>
    <!-- 搜索区域 -->
    <view class="search-box">
       <mySearch @click="goSearch"></mySearch>
    </view>
    <!-- 轮播图区域 -->
    <swiper :autoplay="true" :circular="true" :indicator-dots="true" :duration="1000">
      <swiper-item v-for="(item,i) in swiperImgList" :key="i">
        <navigator class="swiper-item" :url="item.navigator_url">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 分类导航区域 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,i) in cateNavList" :key="i" @click="cateHandle(item)">
        <image class="nav-img" :src="item.image_src"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorList" :key="i">
        <image :src="item.floor_title.image_src" mode="widthFix"></image>
        <view class="floor-img-box">
          <navigator class="left-img-box" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
          <view class="right-img-box">
            <navigator class="right-img-item" v-for="(_item,_i) in item.product_list" :key="_i" v-if="_i !== 0" :url="_item.url">
              <image :src="_item.image_src" :style="{width:_item.image_width + 'rpx'}" mode="widthFix"></image>
            </navigator>
          </view>
        </view>
      </view>
      
    </view>
  </view>
</template>

<script>
  import { getFloorList, getSwiperList,navgation } from "../../api/request.js"
import badge from '../../mixins/tabbar-badge.js'
  export default {
    mixins:[badge],
    data() {
      return {
        // 轮播图图片
        swiperImgList:[],
        // 分类导航数据
        cateNavList:[],
        //楼层数据
        floorList:[]
      };
    },
    methods:{
      // 获取轮播图数据
      async getSwiper(){
        const {data:res} = await getSwiperList()
        if(res.meta.status !== 200){
          return uni.$showMsg()
        }
        this.swiperImgList = res.message
        // console.log(this.swiperImgList);
      },
      // 获取分类导航数据
      async getCateNav(){
        const {data: res} = await navgation()
        console.log(res);
        if(res.meta.status !== 200){
          return uni.$showMsg()
        }
        this.cateNavList = res.message
      },
      // 点击跳转到分类页面
      cateHandle(item){
        if(item.name === '分类'){
          uni.switchTab({
            url:"/pages/cate/cate"
          })
        }
      },
      // 获取楼层数据
      async getFloor(){
        const {data: res} = await getFloorList()
        if(res.meta.status !== 200) return uni.$showMsg()
        res.message.forEach(floor => {
          floor.product_list.forEach(prod => {
            prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
      },
      // 跳转到搜索页面
      goSearch(){
        uni.navigateTo({
            url: '/subpkg/search/search'
          })
      },
    
    },
   
    created(){
      this.getSwiper()
      this.getCateNav()
      this.getFloor()
    }
  }
</script>

<style lang="scss">
  // 搜索框
  .search-box{
    position: sticky;
    top: 0;
    z-index: 999;
  }
  // 轮播图
swiper {
 height: 330rpx;

 .swiper-item,
 image {
   width: 100%;
   height: 100%;
 }
}
// 分类导航
.nav-list {
  display: flex;
  justify-content: space-around;
  margin: 15px 0;

  .nav-img {
    width: 128rpx;
    height: 140rpx;
  }
}
// 楼层
.floor-img-box{
  display: flex;
  padding-left: 10rpx;
}
.right-img-box{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

</style>
